//
//  SoilAndLightTypeViewController.m
//  PlotMate
//
//  Created by Brian Boyle on 05/04/2012.
//  Copyright (c) 2012 Brian Boyle. All rights reserved.
//

#import "SoilAndLightTypeViewController.h"
#import "CreatePlotTableViewController.h"

@interface SoilAndLightTypeViewController()
@property (nonatomic, strong) NSString *selectedItem;
@end

@implementation SoilAndLightTypeViewController
@synthesize headingLabel = _headingLabel;
@synthesize picker = _picker;
@synthesize pickerArray = _pickerArray;
@synthesize selectedItem = _selectedItem;
@synthesize delegate = _delegate;
@synthesize headingText = _headingText;

#pragma mark - View lifecycle


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    int currentRow = [self.picker selectedRowInComponent:0];
    self.selectedItem = [self.pickerArray objectAtIndex:currentRow];
    self.headingLabel.text = self.headingText;
    self.headingLabel.font = [UIFont fontWithName:@"MV Boli" size:16];
    self.headingLabel.textColor = [UIColor colorWithRed:0 green:0.275 blue:0.118 alpha:1];
}

- (void)viewDidUnload
{
    [self setHeadingLabel:nil];
    [self setPicker:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Picker View Delegate

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.selectedItem = [self.pickerArray objectAtIndex:row];
}

#pragma mark - Picker View Datasource

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [self.pickerArray count];
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [self.pickerArray objectAtIndex:row];
}

- (IBAction)cancelButtonPressed:(id)sender 
{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)doneButtonPressed:(id)sender 
    {
        [self.navigationController popViewControllerAnimated:YES];
        [self.delegate soilOrLightSelectedWithValue:self.selectedItem];
}
@end
